﻿#pragma once

_NAMESPACE_BEGIN

using namespace std;

/// 日志管理类
class Log
{
public:

	/// 单体类声明
	SINGLETON_HELPER(Log)

	/// 构造
	Log();

	/// 析构
	~Log();

public:

	/// 输出信息到控制台窗口，并保存到日志文件

	template<typename T>
	void SaveLog(T info, bool clock = true)
	{
		string time;
		
		if(clock)
		{
			Clock::GetSysTime(time);
		}
		
		string log;

		log = boost::lexical_cast<string>(info);
		
		string logInfo;
		if(clock)
		{
			logInfo	= time + ": " + log;
		}
		else
		{
			logInfo = log;
		}

		#ifdef NR_DEBUG
			cout<<logInfo<<endl;
		#endif

		out<<logInfo<<endl;
	}

protected:

	/// 文件流
	ofstream out;
};


/// 方便使用的保存日志宏
#define SAVE_LOG(x) NatRacing::Log::Instance()->SaveLog(x)
#define SAVE_LOG_NENDL(x) NatRacing::Log::Instance()->SaveLog(x,false);


_NAMESPACE_END